package com.imageim.yimirror.ui.fragment;

import android.graphics.Color;
import android.widget.ImageView;
import android.widget.TextView;

import com.imageim.yimirror.R;
import com.imageim.yimirror.base.BaseFragment;
import com.imageim.yimirror.base.Constants;
import com.imageim.yimirror.bean.analysisPhoto.PhotoNoBean;
import com.imageim.yimirror.common.util.UserUtil;
import com.nineoldandroids.animation.ObjectAnimator;

import butterknife.BindView;

/**
 * Created by Yuaihen.
 * on 2018/12/4
 * 男女身线图 + 参考值图
 */
public class BodyLineWithPhotoFragment extends BaseFragment {

    @BindView(R.id.tv_total_desc)
    TextView mTvTotalDesc;
    @BindView(R.id.tv_neck_param)
    TextView mTvNeckParam;
    @BindView(R.id.iv_neck_photo)
    ImageView mIvNeckPhoto;
    @BindView(R.id.tv_neck_param_desc)
    TextView mTvNeckParamDesc;
    @BindView(R.id.tv_waist_param)
    TextView mTvWaistParam;
    @BindView(R.id.iv_waist_photo)
    ImageView mIvWaistPhoto;
    @BindView(R.id.tv_waist_param_desc)
    TextView mTvWaistParamDesc;
    @BindView(R.id.tv_long_leg_param)
    TextView mTvLongLegParam;
    @BindView(R.id.iv_long_leg_photo)
    ImageView mIvLongLegPhoto;
    @BindView(R.id.tv_long_leg_param_desc)
    TextView mTvLongLegParamDesc;
    @BindView(R.id.tv_small_leg_param)
    TextView mTvSmallLegParam;
    @BindView(R.id.iv_small_leg_photo)
    ImageView mIvSmallLegPhoto;
    @BindView(R.id.tv_small_leg_param_desc)
    TextView mTvSmallLegParamDesc;
    @BindView(R.id.iv_body_line)
    ImageView mIvBodyLine;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_body_line_with_photo;
    }

    @Override
    protected void initListener() {
    }

    @Override
    protected void initData() {
        PhotoNoBean photoNoBean = UserUtil.getBeanByGson(Constants.BODY_LINE_PARAM, PhotoNoBean.class);
        int gender = UserUtil.getGender();
        int color = Color.parseColor("#63ff3a");
        if (gender == 1) {
            mIvNeckPhoto.setImageResource(R.drawable.iv_neck_man_fragment);
            mIvWaistPhoto.setImageResource(R.drawable.iv_waist_man_fragment);
            mIvLongLegPhoto.setImageResource(R.drawable.iv_long_leg_man_fragment);
            mIvSmallLegPhoto.setImageResource(R.drawable.iv_small_leg_man_fragment);
            mIvBodyLine.setImageResource(R.drawable.iv_man_body_line);
            color = Color.parseColor("#63ff3a");
        } else if (gender == 2) {
            mIvNeckPhoto.setImageResource(R.drawable.iv_neck_woman_fragment);
            mIvWaistPhoto.setImageResource(R.drawable.iv_waist_woman_fragment);
            mIvLongLegPhoto.setImageResource(R.drawable.iv_long_leg_woman_fragment);
            mIvSmallLegPhoto.setImageResource(R.drawable.iv_small_leg_woman_fragment);
            mIvBodyLine.setImageResource(R.drawable.iv_woman_body_line);
            color = Color.parseColor("#f63854");
        }
        mTvNeckParam.setTextColor(color);
        mTvWaistParam.setTextColor(color);
        mTvLongLegParam.setTextColor(color);
        mTvSmallLegParam.setTextColor(color);
        //         set param to view
        if (photoNoBean != null && photoNoBean.getPercentages() != null) {
            PhotoNoBean.BodyLineParam percentages = photoNoBean.getPercentages();
            mTvNeckParam.setText(String.format("脖子：%.3f", percentages.getPercentageOne()));
            mTvWaistParam.setText(String.format("腰身：%.3f", percentages.getPercentageTwo()));
            mTvLongLegParam.setText(String.format("腿长：%.3f", percentages.getPercentageThree()));
            mTvSmallLegParam.setText(String.format("小腿长：%.3f", percentages.getPercentageFour()));
            mTvNeckParamDesc.setText(percentages.getPercentageOneDesc());
            mTvWaistParamDesc.setText(percentages.getPercentageTwoDesc());
            mTvLongLegParamDesc.setText(percentages.getPercentageThreeDesc());
            mTvSmallLegParamDesc.setText(percentages.getPercentageFourDesc());
            mTvTotalDesc.setText(percentages.getFiveDesc());
        }
        startAnim(1000);
    }

    public void startAnim(long duration) {
        ObjectAnimator fadeIn = ObjectAnimator.ofFloat(mIvBodyLine, "alpha", 0.4f, 1);
        fadeIn.setDuration(duration);
        fadeIn.start();
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            startAnim(500);
        }
    }
}
